package com.acme.bankapp.domain.bank;

import com.acme.exceptions.NotEnoughFundsException;

public class SavingAccount extends AbstractAccount {

	public SavingAccount(double amount) {
		super(amount);
		this.accountInfo.append("Account initial amount " + amount + "\n");
	}
	
	@Override
	public void withdraw(double amount) throws NotEnoughFundsException {
		if(amount >= 0) {
			if(this.balance >= amount) {
				this.balance -= amount;
				this.accountInfo.append("Withdrawed: " + amount + "\n");
			} else {
				throw new NotEnoughFundsException("Not enough funds!");
			}
		} else {
			throw new IllegalArgumentException("amount should be non-negative!");
		}
	}

	@Override
	public double maximumAmountToWithdraw() {
		return this.balance;
	}

	@Override
	public String getAccountType(Account account) {
		return "SavingAccount";
	}

	@Override
	public boolean equals(Object obj) {
		if(this == obj) return true;
		if(obj == null) return false;
		SavingAccount other = (SavingAccount)obj;
		if(this.balance != other.balance) return false;
		if(this.id != other.id) return false;
		if(this.accountInfo.toString().equals(other.accountInfo.toString())) return false;
		return true;
	}

	@Override
	public int hashCode() {
		return super.hashCode();
	}

	@Override
	public int toDecimalValue() {
		return (int)Math.round(this.maximumAmountToWithdraw());
	}
	
}
